﻿using System;
using System.Collections.Generic;
using System.Linq;
using Coleotrack.Core.Helper;
using Coleotrack.Data.Contracts;

namespace Coleotrack.Data
{
    public class User : Entity, IValidation
    {
        public virtual string Name
        {
            get; 
            set;
        }

        public virtual string Email
        {
            get;
            set;
        }

        public virtual string Password
        {
            get;
            set;
        }

        public virtual bool Active
        {
            get;
            set;
        }

        public virtual UserProfile Profile
        {
            get; set;
        }

        public virtual IList<Role> Roles
        {
            get; set;
        }

        public virtual DateTime Created
        {
            get; set;
        }

        public virtual string PasswordRequestCode
        {
            get;
            set;
        }

        public virtual bool IsPasswordRequested()
        {
            return !string.IsNullOrEmpty(PasswordRequestCode);
        }

        public virtual bool IsValid()
        {
            return GetRuleViolations().Count() == 0;
        }

        public virtual IEnumerable<RuleViolation> GetRuleViolations()
        {
            yield break;
        }

        public virtual string ActivationCode
        {
            get
            {
                return string.Format("{0}/{1}", Name, Created).Md5();
            }
        }
    }
}
